package com.glela.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.glela.platform.constant.ErrorEnum;
import com.glela.platform.model.Advertisement;
import com.glela.platform.model.response.ResponseBaseModel;
import com.glela.platform.model.response.ResponseResultModel;
import com.glela.platform.service.AdvertisementService;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "/advertisement")
public class AdvertisementController {

private static Logger logger = LoggerFactory.getLogger(UserController.class);
	
	@Autowired
	private AdvertisementService advertisementService;
	
	/**
	 * 开机广告
	 * 
	 * @param requestUserSet
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAdvertisement", method = RequestMethod.POST, consumes = "application/json")
	public ResponseEntity<?> selectAdvertisement(HttpServletRequest request) {
		try {
//			Advertisement advertisement = advertisementService.selectAdvertisement(request);
			Advertisement advertisement = advertisementService.selectAdvertisementNew(request);
			return new ResponseEntity<>(new ResponseResultModel<Advertisement>(advertisement), HttpStatus.OK);
		} catch (Exception e) {
			logger.error("开机广告异常:", e);
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
		}
	}
	/**
	 * @Description: 开机广告（新接口）
	 * @Author: zhangrenjie
	 * @Date: 2018/1/12 17:05
	 *
	 */
	@ResponseBody
	@RequestMapping(value = "/selectAdvertisementNew", method = RequestMethod.POST, consumes = "application/json")
	public ResponseEntity<?> selectAdvertisementNew(HttpServletRequest request) {
		try {
			Advertisement advertisement = advertisementService.selectAdvertisementNew(request);
			return new ResponseEntity<>(new ResponseResultModel<Advertisement>(advertisement), HttpStatus.OK);
		} catch (Exception e) {
			logger.error("开机广告异常:", e);
			return new ResponseEntity<>(new ResponseBaseModel(ErrorEnum.C20000), HttpStatus.OK);
		}
	}
}
